//
//  AppDelegate+Setup.m
//  BillRecords
//
//  Created by admin on 2018/9/19.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "AppDelegate+Setup.h"
#import <IQKeyboardManager/IQKeyboardManager.h>
#import <AFNetworkReachabilityManager.h>
#import <UMCommon/MobClick.h>
#import <UMCommon/UMConfigure.h>

@implementation AppDelegate (Setup)

- (void)setupNav
{
    // 全局设置 nav
    UINavigationBar *navBar = [UINavigationBar appearance];
//    navBar.shadowImage = [UIImage new];
    navBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor], NSFontAttributeName : [UIFont boldSystemFontOfSize:18]};
//    navBar.tintColor = [UIColor blackColor];    // 可改变系统自带的返回按钮的颜色
    navBar.barTintColor = [UIColor whiteColor];

    // 全局设置 UIBarButtonItem，也就是导航栏左右两边的按钮
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor], NSFontAttributeName : [UIFont systemFontOfSize:16]} forState:UIControlStateNormal];
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor], NSFontAttributeName : [UIFont systemFontOfSize:16]} forState:UIControlStateHighlighted];
   
}

- (void)setupKeyboard
{
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
    [IQKeyboardManager sharedManager].toolbarDoneBarButtonItemText = @"确定";
    
}


- (void)setToastManager
{
    CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle];
//    style.backgroundColor = [UIColor blackColor];
    style.titleColor = [UIColor whiteColor];
    style.titleFont = [UIFont systemFontOfSize:14];
    style.messageFont = [UIFont systemFontOfSize:14];
    style.verticalPadding = 8;
    style.horizontalPadding = 10;
    style.cornerRadius = 6;
    [CSToastManager setSharedStyle:style];
    
    [CSToastManager setDefaultDuration:1.0];    // 默认显示1秒
    [CSToastManager setDefaultPosition:CSToastPositionCenter];  // 默认位置
}

- (void)setupUM
{
    // 初始化
    [UMConfigure initWithAppkey:UMAPP_KEY channel:nil];
    
    // 自动采集页面
    [MobClick setAutoPageEnabled:YES];
}

// 网络变化监听
- (void)networkReachability
{
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if (status == AFNetworkReachabilityStatusNotReachable) {
            [self.window makeToast:@"网络不给力"];
        } else if (status == AFNetworkReachabilityStatusReachableViaWiFi){
            [self.window makeToast:@"WIFI网络"];
        }
    }];
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
}


@end
